package com.atguigu.boot;

import com.atguigu.boot.bean.Pet;
import com.atguigu.boot.bean.User;
import com.atguigu.boot.config.MyConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;

import javax.jws.soap.SOAPBinding;

/**
 * @author yuen
 * @date 2021-04-07 13:18
 * 这是一个SpringBoot应用
 */
@SpringBootApplication
/*@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan("com.atguigu.boot")*/
@EnableAutoConfiguration
@ImportResource("classpath:beans.xml")
public class MainApplication {
    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(MainApplication.class, args);

        //2.查看容器里面的组件
        String[] names = run.getBeanDefinitionNames();
        for (String name : names) {
            System.out.println(name);
        }

        int beanDefinitionCount = run.getBeanDefinitionCount();
        System.out.println(beanDefinitionCount);

        //3.从容器中获取组件

        Pet tom01 = run.getBean("tomcatPet", Pet.class);
        Pet tom02 = run.getBean("tomcatPet", Pet.class);
        System.out.println(tom01 == tom02);

        MyConfig bean = run.getBean(MyConfig.class);
        System.out.println(bean);


        //5.获取组件

        String[] beanNamesForType = run.getBeanNamesForType(User.class);
        System.out.println("=====================");
        for (String s : beanNamesForType) {
            System.out.println(s);
        }

        boolean haha = run.containsBean("haha");
        boolean hehe = run.containsBean("hehe");
        System.out.println(haha);
        System.out.println(hehe);


    }

}
